<template>
  <div class="boxs">
    <div class="f1">
      <ul>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组30.png" alt="" />
            <img class="icon2" src="@/assets/PC/金融服务/组31.png" alt="" />
          </div>
          <span>企业认证</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组33.png" alt="" />
            <img class="icon2" src="@/assets/PC/金融服务/组31.png" alt="" />
          </div>
          <span>填写企业信息</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组34.png" alt="" />
            <img class="icon2" src="@/assets/PC/金融服务/组31.png" alt="" />
          </div>
          <span>填写买方信息</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/组36.png" alt="" />
            <img class="icon2" src="@/assets/PC/金融服务/组31.png" alt="" />
          </div>
          <span>填写账款信息</span>
        </li>
        <li>
          <div class="icon">
            <img class="icon1" src="@/assets/PC/金融服务/005.png" alt="" />
          </div>
          <span>业务提交完成</span>
        </li>
      </ul>
    </div>
    <div class="f2">
      <ul class="ul">
        <li>
          <el-form
            class="bbbb"
            :model="form"
            label-width="150px"
            :rules="rules"
          >
            <el-form-item label="上半年营业收入" prop="a">
              <el-input
                class="input-with-select"
                @blur="costChangeA"
                @focus="
                  () => {
                    this.form.a = remoney(this.form.a);
                  }
                "
                @input="limitInput($event, 'a')"
                v-model="form.a"
                placeholder=""
              >
                <template #append>
                  <el-select v-model="form.d" placeholder="请选择">
                    <el-option label="人民币" value="人民币"></el-option>
                    <el-option label="美元" value="美元"></el-option>
                    <el-option label="欧元" value="欧元"></el-option>
                    <el-option label="英镑" value="英镑"></el-option>
                    <el-option label="日元" value="日元"></el-option>
                    <el-option label="港币" value="港币"></el-option>
                  </el-select>
                </template>
              </el-input>
            </el-form-item>
          </el-form>
          <el-form :model="form" label-width="150px" :rules="rules">
            <el-form-item label="主营市场" prop="b">
              <el-input v-model="form.b" placeholder=""></el-input>
            </el-form-item>
          </el-form>
        </li>
        <li>
          <el-form :model="form" label-width="150px" :rules="rules">
            <el-form-item label="主营产品" prop="c">
              <el-input v-model="form.c" placeholder=""></el-input>
            </el-form-item>
          </el-form>
          <el-form :model="form" label-width="150px" :rules="rules">
            <el-form-item label=" " prop="">
              <el-input style="visibility: hidden"></el-input>
            </el-form-item>
          </el-form>
        </li>
      </ul>
      <!-- 上一步/保存/提交 按钮 -->
      <div class="submit">
        <button
          class="btn btn3"
          @click="goNextFlow()"
          v-bind:class="{
            actives: submitMessage == '提交中',
          }"
        >
          {{ submitMessage }}
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import { myPostFetch } from "@/utils";
import { ElMessage } from "element-plus";
export default {
  data() {
    return {
      submitMessage: "下一步",
      loading: false,
      radio: "",
      isLock: false,
      procedureId: "", // 产品ID状态变量
      productcode: "", //产品编号
      productname: "", //产品名称
      show01: "", //产品名称码值
      index: "",
      c1: false,
      form: {
        a: "",
        b: "",
        c: "",
        d: "人民币",
        applyId: "",
        spid: "",
      },
      // 用户填写资料表格
      addform: {
        a: "",
        b: "",
        c: "",
      },
      // 表单验证
      rules: {
        a: [{ required: true, message: " ", trigger: "blur" }],
        b: [{ required: true, message: " ", trigger: "blur" }],
        c: [{ required: true, message: " ", trigger: "blur" }],
      },
    };
  },
  // 生命周期方法
  mounted() {
    // 从路由地址中获取产品ID,保存到状态变量中
    this.procedureId = localStorage.getItem("productcodeId");
    this.productcode = localStorage.getItem("productcode");
    this.productname = localStorage.getItem("productname");
    this.BusinessSpProductapplys0();
  },
  methods: {
    // 调用产品申请第0步接口
    async BusinessSpProductapplys0() {
      let params = {
        productid: this.procedureId,
      };
      let url = "/api/hubeibusienss/CKBLRZHXKJApplyhx";
      let { data } = await myPostFetch(url, params);
      if (data == 0) {
        this.form.applyId = 0;
      }
      if (data != 0) {
        let info = data.kjApplyInfo;
        this.form.a = info.operatingincome;
        this.form.b = info.mainmarket;
        this.form.c = info.mainproduct;
        this.form.applyId = info.applyid;
        this.form.spid = info.spid;
        let entoutstanding = info.operatingincome.split(" ")[0];
        console.log(entoutstanding);
        this.form.d = info.operatingincome.split(" ")[1];
        // 上半年营业收入
        if (parseInt(Number(entoutstanding), 10) != Number(entoutstanding)) {
          this.form.a = Number(entoutstanding).toLocaleString();
        } else {
          this.form.a = Number(entoutstanding).toLocaleString() + ".00";
        }
        this.addform.a = entoutstanding;
        return;
      }
    },
    // 前往下一个流程， 调用产品申请1接口将客户填写的数据返回至后端
    async goNextFlow() {
      if (this.submitMessage == "提交中") return;
      let { b, c, d } = this.form;
      let { a } = this.addform;
      if (a.trim() == "" || b.trim() == "" || c.trim() == "" || d.trim() == "")
        return ElMessage.error("请输入内容");
      this.submitMessage = "提交中";
      let params = {
        operatingincome: a + " " + d,
        mainmarket: b,
        mainproduct: c,
        productcood: this.productcode,
        productname: this.productname,
        productid: this.procedureId,
        applyid: this.form.applyId,
      };
      let url = "/api/hubeibusienss/addckblrz";
      let data = await myPostFetch(url, params);
      if (data.code == 100) {
        localStorage.setItem("applyid", data.data.applyid);
        localStorage.setItem("kjid", data.data.id);
        this.$router.push(`/ckblrz2`);
        this.submitMessage = "下一步";
      } else {
        this.submitMessage = "下一步";
      }
    },
    // 表单格式转换
    costChangeA(e) {
      let a = Number(e.target.value);
      a = a.toFixed(2);
      if (a == "NaN") return (this.form.a = "");
      this.addform.a = this.form.a;
      //获取输入的数据，若不写这行，数据可能输不进去
      this.form.a = e.target.value;
      //将用户输入的数据，自动转换为带千分符的
      this.form.a = this.fmoney(this.form.a);
    },

    // 票面金额
    limitInput(value, name) {
      this.addform[name] =
        ("" + value) // 第一步：转成字符串
          .replace(/[^\d^\.]+/g, "") // 第二步：把不是数字，不是小数点的过滤掉
          .replace(/^0+(\d)/, "$1") // 第三步：第一位0开头，0后面为数字，则过滤掉，取后面的数字
          .replace(/^\./, "0.") // 第四步：如果输入的第一位为小数点，则替换成 0. 实现自动补全
          .match(/^\d*(\.?\d{0,2})/g)[0] || "";
    },
    //千分位格式化：10000转为10,000.00
    fmoney(s, n) {
      if (s == "" || s == null || (s == undefined) | isNaN(Number(s))) {
        return s;
      }
      s = Number(s) ? Number(s) : s;
      n = (n || n == 0) && n > -1 && n <= 20 ? n : 2;
      s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";
      var l = s.split(".")[0].split("").reverse();
      var r = s.split(".")[1];
      var t = "";
      for (var i = 0; i < l.length; i++) {
        t += l[i] + ((i + 1) % 3 == 0 && i + 1 != l.length ? "," : "");
      }
      if (n > 0) {
        r = "." + r;
      } else if (n == 0) {
        r = "";
      }
      let returnT = t.split("").reverse().join("") + r;
      //负数处理
      if (returnT[0] == "-" && returnT[1] == ",") {
        returnT = "-" + returnT.substring(2);
      }
      return returnT;
    },
    //千分位反格式化:10,000.00转为10000.00
    remoney(s) {
      let str = "";
      if (s) {
        str = String(s).replace(/,/g, "");
      }
      if (s && (s + "").indexOf(".") > -1 && Number(str)) {
        return String(s).replace(/[^\d\.-]/g, "");
      } else if (s && Number(str)) {
        return str;
      } else {
        return s;
      }
    },
  },
};
</script>

<style lang="scss" scoped>
.boxs {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  height: 450px;
  overflow: hidden;
  .f1 {
    margin-top: 20px;
    ul {
      display: flex;
      align-items: center;
      li {
        display: flex;
        flex-direction: column;
        height: 40px;
        .icon {
          .icon1 {
            width: 40px;
          }
          .icon2 {
            width: 120px;
            height: 3px;
            margin: 0 8px;
          }
        }
        span {
          font-size: 14px;
          font-family: Source Han Sans SC;
          font-weight: 400;
          color: #999999;
          margin-left: -19px;
          margin-top: 3px;
        }
      }
    }
  }
  .unit {
    z-index: 999;
    position: relative;
    @media only screen and (min-width: 1580px) and (max-width: 1950px) {
      left: 537px;
      top: 75px;
    }
    left: 537px;
    top: 55px;
    font-size: 16px;
    font-family: Source Han Sans SC;
    font-weight: 400;
    color: #b3b3b3;
    font-size: 14px;
    color: #606266;
  }
  .f2 {
    margin-top: 7%;
    width: 100%;
    ul {
      li {
        position: relative;
        width: 100%;
        margin-bottom: 18px;
        height: 50px;
        display: flex;
        justify-content: center;
        .message {
          margin-top: -11px;
          font-size: 12px;
          font-family: Source Han Sans SC;
          font-weight: 300;
          color: #ef2d46;
        }
      }
    }
  }
  .submit {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 100%;
    height: 50px;
    margin: 60px 0 5px 0;
    cursor: pointer;
    .btn {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 180px;
      height: 34px;
      background: #0a7be0;
      border-radius: 4px;
      font-size: 16px;
      font-family: Source Han Sans SC;
      font-weight: 300;
      color: #ffffff;
      margin-right: 30px;
      &.actives {
        background-color: rgba(10, 123, 224, 0.6);
      }
    }
  }
}
/* 输入框样式  */
::v-deep(.el-input__inner) {
  box-sizing: border-box;
  width: 320px;
  height: 39px;
  font-size: 15px;
  border: 1px solid #e0e0e0;
  border-radius: 0px;
  padding: 10px 10px;
  color: #606266;
  outline: 0;
  line-height: 35px !important;
}
::v-deep(.bbbb .el-input__inner) {
  width: 200px;
}
::v-deep(.el-select .el-input input) {
  width: 100px;
}
::v-deep(.input-with-select .el-input-group__prepend) {
  background-color: #fff;
}
::v-deep(.el-input__wrapper) {
  padding: 1px 10px;
}
</style>
<style lang="scss"></style>
